#ifndef _UICOMMUNICATOR_H_
#define _UICOMMUNICATOR_H_

#include <QtDBus>

#include "daemon.h"

#include <iostream>
using std::cerr;
using std::cout;

namespace Tubox {
class UICommunicator : public QObject {
public:
	UICommunicator(Daemon* daemon) : daemon(daemon) {
		if (!QDBusConnection::sessionBus().isConnected()) {
			cerr << "Cannot connect to the D-Bus session bus.\n" <<
					"To start it, run:\n" <<
					"\teval `dbus-launch --auto-syntax`\n";
		}
		if (!QDBusConnection::sessionBus().registerService("com.tubox.Daemon.Ui")) {
			cerr << QDBusConnection::sessionBus().lastError().message().toStdString() << endl;
		}
		else {
			QDBusConnection::sessionBus().registerObject("/", this, QDBusConnection::ExportAllSlots);
		}
	}

public slots:
	QString askCopy(const QString& oldPath, const QString& name, const QString& newPath) {
		daemon->askCopy(oldPath, name, newPath);
		return "";
	}

	QString askMove(const QString& oldPath, const QString& name, const QString& newPath) {
		daemon->askMove(oldPath, name, newPath, name);
		return "";
	}

	QString askRename(const QString& path, const QString& oldName, const QString& newName) {
		daemon->askMove(path, oldName, path, newName);
		return "";
	}

	QString askDelete(const QString& path, const QString& name) {
		cout << "Funcionou" << endl;
		daemon->askDelete(path, name);
		return "";
	}

	QString askMkdir(const QString& path, const QString& name) {
		daemon->askMkdir(path, name);
		return "";
	}
	
	QString askDisconnect() {
		daemon->askLogoff();
		return "";
	}

private:
	Daemon* daemon;
};

}

#endif // _UICOMMUNICATOR_H_
